<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<div class="pro_list fr"  >
   <div class="title"  >
   	 <span class="titletxt">您现在的位置：</span>
     <ul> 
       <li class="root">会员中心</li>  
       <li>用户管理</li>        
       <li>收货地址管理</li>            
     </ul>
   </div>
  <c:if test="${not empty ret }">
   	<c:if test="${ret.code ne '200'}">
   		<script type="text/javascript">alertError('${ret.result}');</script>
   		<div id=messager class="messager" >
	         <div class="contentmsg">
	             <h5>提示信息～！</h5>
	             <ul>
	                <li>${ret.result}</li>
	             </ul>
	        </div>
	     <div class="closer" onClick="showHideLayer('messager');" title="关闭"></div>
	    </div>
   	</c:if>
   </c:if>
<br/>
   <div  class="easyui-panel" title="我的收货地址"  style="">
    
    <div data-options="region:'center',split:true" style="width: 100%;height: 480px">
		<table id="tableGrid"></table>
	</div>
	
</div>
</div>
<script>
var toolbar = [{
	text:'新增地址',
    iconCls:'icon-add',
    handler:function(){
    	openAddressAddWindow();
    }
}];
var addressTable;
$(function(){
	initAddress();
});

function initAddress(){
	addressTable = $('#tableGrid').pDataGrid({
		toolbar:toolbar,
		 columns:[[
		          {field:'action',title:'操作',align:'center',formatter:function(value,row,index){
						return '<a href="#"  onclick="openAddressUpdateWindow('+row.buyerAddressId+')">修改</a> | <a href="#" onclick="deleteBuyerAddress('+row.buyerAddressId+','+index+')">删除</a> ';
		          		}},
	          	  {field:'areaName',title:'收货地址',align:'center',sortable:true},
	              {field:'address',title:'街道地址',align:'center',sortable:true},
	              {field:'zip',title:'邮编',align:'center',sortable:true},
	              {field:'consignee',title:'收货联系人',align:'center',sortable:true},
	              {field:'phone',title:'收货联系电话',align:'center',sortable:true},
	              {field:'isDefalut',title:'是否默认地址',align:'center',sortable:true,formatter:function(value){
						if(value=="0"){
							return '否';
						}else{
							return '是';
						}
		          }}
		          ]],
		    url:'<c:url value="/buyerAddress/searchPageBuyerAddress.s"/>',  
		    pagination:false,
		    pageSize:20,
		    singleSelect:false,
		    rownumbers:true,
			nowrap: true
	}); 
}
function openAddressAddWindow(){
	$.pmsDialog({
		id:"win_address_add",
		title:'新增收货地址',
		method:'post',
		href:'<c:url value="/views/jsp/center/address/buyer_address_add.jsp"/>',
		width:500,
		height:350,
		buttons:[]
	});
}
function openAddressUpdateWindow(buyerAddressId){
	var param = {"buyerAddressId":""+buyerAddressId+""};
	$.pmsDialog({
		id:"win_address_update",
		title:'修改收货地址',
		method:'post',
		href:'<c:url value="/views/jsp/center/address/buyer_address_update.jsp"/>',
		width:500,
		height:350,
		params:param,
		buttons:[]
	});
}
function deleteBuyerAddress(buyerAddressId,i){
	if(confirm("确定删除?")){
		//alert(buyerAddressId+'  111');
		var param = {"buyerAddressId":buyerAddressId};
		$.pmsAjax({
			url:'<c:url value="/buyerAddress/deleteBuyerAddress.s"/>',
			data:param,
			success:function(data){
				if(data.code=="200"){
					alertShow("删除成功");
					addressTable.refresh();
				}else{
					alertError(data.resultMessage);
				}
			}
		});
	}
}

</script>